<template>
	
  <div class="divBox">
	  <!-- aa -->
    <el-card :bordered="false" dis-hover class="ivu-mt box-card">
		
     <!-- <el-form
        ref="tableFrom"
        :model="tableFrom"  
        :label-width="labelWidth"
        :label-position="labelPosition"
        @submit.native.prevent
      > -->
	   <el-form size="small" inline label-width="120px">
		   
            <el-form-item label="活动类型：" clearable style="display:block;">
              <el-radio-group v-model="tableFrom.factor" type="button" @on-change="selectChangeFactor()" class="mr">
                <el-radio :label="1">幸运分抽取</el-radio>
     <!--           <el-radio :label="3">订单支付</el-radio>
                <el-radio :label="4">订单评价</el-radio> -->
              </el-radio-group>
            </el-form-item>     
          
         
           <!-- <el-form-item label="时间选择：" style="display: block;">
              <el-radio-group v-model="tableFrom.data" type="button" @on-change="selectChange(tableFrom.data)" class="mr">
                <el-radio :label="item.val" v-for="(item, i) in fromList.fromTxt" :key="i">{{ item.text }}</el-radio>
              </el-radio-group>
              <el-date-picker
                :editable="false"
                @on-change="onchangeTime"
                :value="timeVal"
                format="yyyy/MM/dd"
                type="daterange"
                placement="bottom-end"
                placeholder="自定义时间"
                style="width: 200px"
              ></el-date-picker>
            </el-form-item> -->  
			<el-form-item label="时间选择：" class="width100" style="display:block;"> 
			 <!-- <el-radio-group v-model="tableFrom.data" type="button" class="mr20" size="small" @change="selectChange(tableFrom.date)">
			    <el-radio-button v-for="(item,i) in fromList.fromTxt" :key="i" :label="item.val">{{ item.text }}</el-radio-button>
			  </el-radio-group> -->
			  <el-date-picker v-model="timeVal" value-format="yyyy/MM/dd" format="yyyy/MM/dd" size="small" type="daterange" placement="bottom-end" placeholder="自定义时间" style="width: 250px;" @change="onchangeTime" />
			</el-form-item>
           
        
            <el-form-item label="奖品类型" style="display:block;">
              <el-radio-group v-model="tableFrom.type" type="button" @on-change="selectType()" class="mr">
                <el-radio :label="item.val" v-for="(item, i) in typeList" :key="i">{{ item.text }}</el-radio>
              </el-radio-group>
            </el-form-item>
         
            <el-form-item label="搜索用户：" label-for="store_name" style="display: block;">
              <!-- <el-input
                search
                enter-button
                placeholder="请输入用户信息"
                v-model="tableFrom.keyword"
                @on-search="userSearchs"
              /> -->
			  <el-input v-model="tableFrom.keyword" @keyup.enter.native="getList(1)" placeholder="请输入用户信息" class="selWidth">
			    <el-button slot="append" icon="el-icon-search" class="el-button-solt" @click="getList(1)" />
			  </el-input>
			  
            </el-form-item>
          
        </el-row>
      </el-form>
      <el-table
        :columns="columns1"
        :data="tableList" 
        :loading="loading"
        highlight-row
        no-userFrom-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
      >
	  
		<el-table-column label="用户信息" min-width="150">
			<template slot-scope="scope" >
			
				<span>{{ scope.row.user.nickname}}({{ scope.row.user.uid }}) </span>
			</template>
		</el-table-column>
       
	   <el-table-column label="奖品信息" min-width="150">
			<template slot-scope="scope">
			  <div class="prize">
			    <img :src="scope.row.prize.image" alt="" />
			    <span>{{ scope.row.prize.name }}</span>
			  </div>
			</template>
		</el-table-column>
    
		
		<el-table-column label="奖品描述" min-width="150">
			<template slot-scope="scope">
			  <div class="prize">
		
				<span v-if="scope.row.coupon_list" >{{ scope.row.coupon_list.mer_name}}</span>
	      <span v-else >{{ scope.row.prize.prompt}}</span>
        

			  </div>
			</template>
		</el-table-column>
		
		
		<!-- <el-table-column label="收货信息" min-width="160">
			<template slot-scope="scope">
			  <div v-if="scope.row.receive_info.name">
			    <div>姓名：{{ scope.row.receive_info.name }}</div>
			    <div>电话：{{ scope.row.receive_info.phone }}</div>
			    <div>地址：{{ scope.row.receive_info.address }}</div>
			    <div v-if="scope.row.receive_info.mark">备注：{{ scope.row.receive_info.mark }}</div>
			  </div>
			</template>
		</el-table-column> -->
		
		
		<el-table-column label="抽奖时间" min-width="160">
		  <template slot-scope="scope">
		    <div>抽奖时间：{{ scope.row.add_time}}</div>
		  </template>
		</el-table-column>
		
		
		
		
		<!-- <el-table-column label="抽奖时间" min-width="150">
			<template slot-scope="scope">
			  <span>{{ scope.row.deliver_info.mark }}</span>
			</template>
		</el-table-column> -->
		
        <!-- <template slot-scope="{ row, index }" slot="receive_info">
          <div v-if="row.receive_info.name">
            <div>姓名：{{ row.receive_info.name }}</div>
            <div>电话：{{ row.receive_info.phone }}</div>
            <div>地址：{{ row.receive_info.address }}</div>
            <div v-if="row.receive_info.mark">备注：{{ row.receive_info.mark }}</div>
          </div>
        </template>
        <template slot-scope="{ row, index }" slot="prize">
          <div class="prize">
            <img :src="row.prize.image" alt="" />
            <span>{{ row.prize.name }}</span>
          </div>
        </template>
        <template slot-scope="{ row, index }" slot="action">
          <a @click="deliver(row, 1)" v-if="row.type == 6 && row.is_deliver === 0">发货</a>
          <a v-else-if="row.type == 6 && row.is_deliver === 1" @click="isDeliver(row)">配送信息</a>
          <Divider type="vertical" v-if="row.type == 6" />
          <a @click="deliver(row, 2)">备注</a>
        </template> --> -->
      </el-table>
      <div class="acea-row row-right page">
        <el-pagination
          :total="total"
          :current-page="tableFrom.page"
          show-elevator
          show-total
          @on-change="pageChange"
          :page-size="tableFrom.limit"
        />
      </div>
    </el-card>
    <!-- 发货-->
    <!-- <el-dialog
      v-model="shipModel"
      width="40%"
      scrollable
      closable
      footer-hide
      :title="!modelTitle ? (modelType === 1 ? '发货' : '备注') : modelTitle"
      :mask-closable="false"
      :z-index="1"
    >
		  <el-form
			v-model="shipModel"
			:ref="modelType === 1 ? 'shipForm' : 'markForm'"
			:model="modelType === 1 ? shipForm : markForm"
			:rules="modelType === 1 ? ruleShip : ruleMark"
			:label-width="80"
		  >
				<el-form-item v-if="modelType === 1" label="快递公司" prop="deliver_name">
				  <el-select v-model="shipForm.deliver_name">
					<el-option v-for="item in locationList" :value="item.value" :key="item.id">{{ item.value }}</el-option>
				  </el-select>
				</el-form-item>
				<el-form-item v-if="modelType === 1" label="快递单号" prop="deliver_number">
				  <el-input v-model="shipForm.deliver_number" placeholder="请输入快递单号"></el-input>
				  <div class="trips" v-if="shipForm.deliver_name == '顺丰速运'">
					<p>顺丰请输入单号 :收件人或寄件人手机号后四位</p>
					<p>例如：SF000000000000:3941</p>
				  </div>
				</el-form-item>
				<el-form-item v-if="modelType === 2" label="备注">
				  <el-input v-model="markForm.mark" placeholder="请输入备注"></el-input>
				</el-form-item>
				<el-form-item>
				  <Button type="primary" @click="ok(modelType === 1 ? 'shipForm' : 'markForm')">提交</Button>
				  <Button @click="cancel('formValidate')" style="margin-left: 8px">关闭</Button>
				</el-form-item>
		</e-form>
    </el-dialog> -->
  </div>
</template>

<script>
import { mapState } from "vuex";
import { lotteryRecordList, lotteryRecordDeliver } from "@/api/lottery";
import { formatDate } from "@/utils/validate";
import { getExpressData } from "@/api/order";
// import { ruleShip, ruleMark } from '../addGoods.vue';
export default {
  name: "lotteryRecordList",
  filters: {
    formatDate(time) {
      if (time !== 0) {
        let date = new Date(time * 1000);
        return formatDate(date, "yyyy-MM-dd hh:mm");
      }
    },
  },
  data() {
    return {
      shipModel: false,
      loading: false,
      locationList: [],
      shipForm: {
        id: "",
        deliver_name: "",
        deliver_number: null,
      },
      markForm: {
        id: "",
        mark: "",
      },
      // ruleShip: ruleShip,
      // ruleMark: ruleMark,
      fromList: {
        title: "选择时间",
        fromTxt: [
          { text: "全部", val: "" },
          { text: "今天", val: "today" },
          { text: "昨天", val: "yesterday" },
          { text: "最近7天", val: "lately7" },
          { text: "最近30天", val: "lately30" },
          { text: "本月", val: "month" },
          { text: "本年", val: "year" },
        ],
      },
      typeList: [
        { text: "全部", val: "" },
        { text: "未中奖", val: "1" },
        // { text: '积分', val: '2' },
        { text: "余额", val: "3" },
        // { text: '红包', val: '4' },
        { text: "平台优惠券", val: "5" },
        { text: "商家优惠券", val: "10" },
        // { text: '商品', val: '6' },
      ],
      columns1: [
        {
          title: "ID",
          key: "id",
          width: 80,
        },
        {
          title: "用户信息",
          slot: "user",
          minWidth: 90,
        },
        {
          title: "奖品信息",
          slot: "prize",
          minWidth: 130,
        },
        {
          title: "奖品描述",
          slot: "user_bill_mark",
          minWidth: 130,
        },
        {
          title: "抽奖时间",
          key: "add_time",
          minWidth: 100,
        },
        // {
        //   title: '收货信息',
        //   slot: 'receive_info',
        //   minWidth: 100,
        // },
        {
          title: "备注",
          slot: "mark",
          minWidth: 100,
        },
        {
          title: "操作",
          slot: "action",
          fixed: "right",
          minWidth: 130,
        },
      ],
      tableList: [],
      grid: {
        xl: 7,
        lg: 10,
        md: 12,
        sm: 24,
        xs: 24,
      },
      tableFrom: {
        keyword: "",
        date: [],
        page: 1,
        limit: 15,
        factor: 6,
      },
      total: 0,
      timeVal: [],
      modelType: 1,
      lottery_id: "",
      modelTitle: "",
    };
  },
  computed: {
    ...mapState("admin/layout", ["isMobile"]),
    labelWidth() {
      return this.isMobile ? undefined : 80;
    },
    labelPosition() {
      return this.isMobile ? "top" : "left";
    },
  },
  created() {
    this.tableFrom.lottery_id = this.$route.query.id;
    this.lottery_id = this.$route.query.id;
    this.getList();
    // this.getExpressData();
  },
  methods: {
    deliver(row, type) {
      this.markForm.id = row.id;
      this.shipForm.id = row.id;
      this.shipForm.deliver_name = "";
      this.shipForm.deliver_number = "";
      this.markForm.mark = row.deliver_info.mark;
      this.modelType = type;
      this.shipModel = true;
    },
    isDeliver(row) {
      this.markForm.id = row.id;
      this.shipForm.id = row.id;
      this.modelType = 1;
      this.modelTitle = "配送信息";
      this.shipModel = true;
      this.shipForm.deliver_name = row.deliver_info.deliver_name;
      this.shipForm.deliver_number = row.deliver_info.deliver_number;
    },
    ok(name) {
      this.$refs[name].validate((valid) => {
        lotteryRecordDeliver(
          this.modelType == 1 ? this.shipForm : this.markForm
        )
          .then((res) => {
            this.$Message.success("操作成功");
            this.shipModel = false;
            this.getList();
            this.shipForm = {
              id: "",
              deliver_name: "",
              deliver_number: null,
            };
            this.modelTitle = "";
            this.markForm = {
              id: "",
              mark: "",
            };
          })
          .catch((err) => {
            this.$Message.error(err.msg);
          });
      });
    },
    cancel() {
      this.modelType = 1;
      this.modelTitle = "";
      this.shipModel = false;
    },
    // 物流公司列表
    getExpressData() {
      getExpressData()
        .then(async (res) => {
          this.locationList = res.data;
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      console.log("this.timeVal", this.timeVal);
      this.tableFrom.data = this.timeVal[0] ? this.timeVal.join("-") : "";
      this.tableFrom.page = 1;
      this.getList();
    },
    // 选择时间
    selectChange(tab) {
      this.tableFrom.page = 1;
      this.tableFrom.date = tab;
      this.timeVal = [];
      this.getList();
    },
    selectType(type) {
      this.tableFrom.page = 1;
      this.timeVal = [];
      this.getList();
    },
    selectChangeFactor() {
      this.tableFrom.page = 1;
      this.timeVal = [];
      this.getList();
    },
    // 列表
    getList() {
      this.loading = true;
      console.log("this.tableFrom", this.tableFrom);
      lotteryRecordList(this.tableFrom)
        .then(async (res) => {
          // alert('yes');
          let data = res.data;
          console.log("this.tableList", data.list);
          this.tableList = data.list;
          this.total = res.data.count;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
          this.$Message.error(res.msg);
        });
    },
    pageChange(index) {
      this.tableFrom.page = index;
      this.getList();
    },
    // 表格搜索
    userSearchs() {
      this.tableFrom.page = 1;
      this.getList();
    },
  },
};
</script>

<style scoped lang="scss">
.tabBox_img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;

  img {
    width: 100%;
    height: 100%;
  }
}

.prize {
  display: flex;
  align-items: center;
}

.prize img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 5px;
}

.trips {
  color: #ccc;
}
</style>
